1. Field of the Invention
This invention relates to a memory rewriting apparatus capable of easily rewriting a memory, and more specifically, it relates to a memory rewriting apparatus at least including a CPU, a RAM, and a nonvolatile memory in which nonvolatile memory programs including various control programs and a rewriting program for rewriting the control programs are stored, whereby when a program update command requesting rewriting of the nonvolatile memory programs is received from the exterior, the memory rewriting apparatus rewrites the nonvolatile memory programs by using the rewriting program stored in the nonvolatile memory.
2. Description of the Related Art
Such a kind of memory rewriting apparatus updates programs by receiving program data from the outside, and rewriting the contents of the nonvolatile memory. (Here, a flash ROM is taken as a typical example.) In this case, even if there arises the necessity of reading the contents of the flash ROM during the time when the contents of the flash ROM are being rewritten, it would be impossible to perform reading out the contents thereof. Thus, in order to solve such an inconvenience, the following measures were taken in the past That is,
(1) A rewriting program for rewriting the contents of a flash ROM is stored in advance in a ROM different from the flash ROM.
(2) A rewriting program is stored in a flash ROM, so that the rewriting program is transferred to a RAM upon rewriting, and is run on the RAM.
(3) A rewriting program is stored in a flash ROM, so that the rewriting program is transferred to a RAM upon rewriting, and then memory maps in the flash ROM and the RAM are exchanged with each other (for instance, see Japanese Patent Application Laid-Open No. 8-185354).
However, the above measures involve the following problems. That is,
In case of (1) above, an additional ROM other than the flash ROM is needed.
In case of (2) above, when an interrupt address is allocated to the flash ROM, data cannot be read upon generation of an interrupt. In other words, interrupt processing cannot be used.
In case of (3) above, though interrupt processing can be used, the positions of the RAM and the flash ROM are mutually exchanged with each other between during normal operation and at the time of rewriting the flash ROM program, so a control or switching program becomes complicated.
This invention is intended to solve the problems as referred to above, and has for its object to provide a memory rewriting apparatus which does not require an additional ROM separately from a flash ROM, and which can use interrupt processing while utilizing a non-complicated program for switching between normal operation and rewriting of the flash ROM.
In order to solve the above-mentioned problems, a memory rewriting apparatus according to the present invention comprises: a copying unit for copying a rewriting program stored in a nonvolatile memory into a RAM upon receipt of an instruction for rewriting the nonvolatile memory; a RAM allocation unit for allocating the RAM, into which copying is carried out by the copying unit, to an area of the nonvolatile memory; and a rewriting execution unit for rewriting the nonvolatile memory by using the rewriting program stored in the RAM allocated by the RAM allocation unit.
According to such a configuration, the contents of the nonvolatile memory can be rewritten by executing the contents of the nonvolatile memory while using the rewriting program stored in the RAM similarly to the execution of the rewriting program stored in the nonvolatile memory, as a result of which it becomes easy to rewrite the nonvolatile memory.
Moreover, a memory rewriting apparatus according to the present invention comprises: a copying unit for copying, upon receipt of an instruction for rewriting a nonvolatile memory, a rewriting program stored in the nonvolatile memory into a first area of a RAM; a RAM allocation unit for allocating the RAM, into which copying is carried out by the copying unit, to an area of the nonvolatile memory; a rewriting execution unit for rewriting the nonvolatile memory by using the rewriting program stored in the RAM allocated by the RAM allocation unit; and a use permission unit for permitting a second area of the RAM to be used as a RAM area upon execution by the rewriting execution unit.
According to such a configuration, the RAM can be used even in the course of rewriting thereof as in the normal operation in which rewriting of the RAM is not executed.
In addition, the present invention resides in a memory rewriting apparatus including at least a CPU, a RAM and a nonvolatile memory which stores therein nonvolatile memory programs including various control programs and a rewriting program for rewriting the various control programs, wherein the apparatus rewrites, upon receipt of a program update command requesting rewriting of the nonvolatile memory programs from the outside, the nonvolatile memory programs by using the stored rewriting program, the apparatus comprising: a memory map switching unit connected with the CPU, the RAM and the nonvolatile memory and adapted to allocate the RAM and the nonvolatile memory to a memory map for a normal operation when it receives from the CPU an instruction indicative of a normal operation time other than a program rewriting operation time, and allocate, upon receipt of an instruction indicative of a program rewriting operation time, the RAM not only to the memory map area but also to another memory map area to which the nonvolatile memory is allocated in the normal operation while moving the nonvolatile memory to a memory map area other than the two memory map areas in which the RAM is allocated and a rewriting execution unit adapted to operate in such a manner that the CPU can copy into the RAM the nonvolatile memory programs stored in the nonvolatile memory that is in a memory map for the normal operation, then generate an instruction indicative of a program rewriting operation, and rewrite the nonvolatile memory programs in the nonvolatile memory which has been moved to the memory map area other than the two memory map areas where the RAM is allocated, in accordance with the rewriting program copied into the RAM allocated to the nonvolatile memory area for the normal operation.
According to such a configuration, the rewriting of the nonvolatile memory programs is carried out by rewriting the nonvolatile memory programs allocated in the areas other than the two areas where the RAM has been allocated by the rewriting program that is copied into the RAM and allocated to the area of the nonvolatile memory at time of normal operation. Accordingly, the CPU understands that only the area where the nonvolatile memory to be rewritten exists has been moved, and that the rewriting program and the RAM do not change their existing areas. As a result, the rewriting program does not become complicated. In addition, even if an interrupt is generated during the program rewriting operation, it can be executed since the area in the memory map of the active rewriting program and the area of the program to be rewritten are different from each other.
Further, in the present invention, the nonvolatile memory comprises a flash ROM, and the CPU has a port output terminal and a first through a third selection output terminal. The memory map switching unit is connected, on one hand, with the port output terminal and the first through third selection output terminals of the CPU, respectively, and, on the other hand, with the flash ROM and the RAM, respectively. The rewriting execution unit comprises a rewriting execution control program given to the CPU, and the CPU sets its port output terminal to a first logic at the time of the normal operation, and to a second logic at the time of rewriting the flash ROM program in accordance with the rewriting execution control program. In addition, the CPU sets it first selection output terminal to the first logic when a low address area is selected, and to the second logic when non-selection is made, and it also sets the second selection output terminal to the first logic when a middle address area is selected, and to the second logic when non-selection is made, and it further sets the third selection output terminal to the first logic when a high address area is selected, and to the second logic when non-selection is made. In the case where the port output terminal is set to the first logic, the memory map switching unit permits the access of the CPU to the RAM when the first selection output terminal is set to the first logic, refuses the access of the CPU to the flash ROM or the RAM in accordance with the logic of the second selection output terminal, and permits the access of the CPU to the flash ROM when the third selection output terminal is set to the first logic. On the other hand, in the case where the port output terminal is set to the second logic, the memory map switching unit permits the access of the CPU to the RAM when the first selection output terminal is set to the first logic, permits the access of the CPU to the flash ROM when the second selection output terminal is set to the first logic, and permits the access of the CPU to the RAM when the third selection output terminal is set to the first logic.
Still further, in the present invention, the memory map switching unit comprises a logical circuit which is connected at its input side with the port output terminal and the first through third selection output terminals, and at its output side with the RAM and the flash ROM.